import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChange} from "@angular/core";
import {CommService} from "../comm-service";
import {LocalStorageService} from "../local-storage-service";
import {MyhttpService} from "../myhttp.service";
import {assertNotNull} from "@angular/compiler/src/output/output_ast";

declare var $: any;

@Component({
  selector: "search-tree",
  template: `
    <div class="row">
      <div class="col-lg-12 treeroom" [style.height]="treeroomh">
        <div id="tree"></div>
      </div>
    </div>
  `,
  styles: [
    ".treeroom{overflow-y: auto}"
  ]
})
export class SearchTreeComponent implements OnInit, OnChanges {
  treetype: string;
  s_ksjhbh: string = "";
  s_ksccbh: string = "";
  treeroomh: string = "0px";

  /**
   *  ####################################################场所查询条件树 ########################################################
   * @param {string} flag
   * "" ----初始化构造
   * "refresh"---刷新场所树
   * "removetree"--删除树实例，并重新生成树
   *
   * */
  initcstree(flag: string): void {
    if (flag === "refresh") {
      $("#tree").jstree("refresh");
      return;
    }
    if (flag == "removetree") {
      // 销毁树，并重新加载
      $("#tree").jstree("destroy");
    }
    const nodelx = this.o.nodelx;
    const cxlxarr = nodelx.split("_");
    const cxlx = cxlxarr.join(",");
    this.createtree_cs(cxlx);
  }

  /**
   * 逗号隔开， 可选值  ksgljg,bzhkd,bms,zhzx,bzhkc
   * @param {string} cxlx
   */
  createtree_cs(cxlx: string): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getcsdata(that.o.id, that.o.type, cxlx, (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {
                  sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          } else {
            that.getcsdata(node.id, node.type, cxlx, (data) => {
              cb(data);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "zhzx": {
          "icon": "fa fa-flag"
        },
        "bzhkc": {
          "icon": "fa fa-server"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const sipuriv = selected.node.data.sipuri;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          sipuri: sipuriv,
        }
      });
    }).on("loaded.jstree", function () {
      if (that.o["clickroot"] === false) {
        return
      }
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  getcsdata(id: string, type: string, cxlx: string, callback: Function): void {
    const url = "ksyw/jcxxgl/slb";
    this.itservice.kwPtPost(url,
      {
        id: id,
        jdlx: type,
        cxlx: cxlx
      }
    ).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
        if (flag) {
          if (flag2) {
            const treeList = resp.treeList;
            const bmslist: any[] = [];
            const notbmslist: any[] = [];
            treeList.forEach((item) => {
              const jdlx = item.jdlx;
              const node = {
                id: item.id,
                type: jdlx,
                text: item.jdmc,
                data: {
                  sipuri: this.commservice.removeSpace(false, item.sipuri)
                },
                li_attr: {
                  title: item.jdmc
                },
                children: true
              }
              const cxlxArr = cxlx.split(",");
              if (cxlxArr.indexOf("bzhkc") == -1) {
                // 查询中没有bzhkc， 那么 zhzx bzhkd bms是子节点， 如果只有ksgljg那么县区ksgljg是子节点
                if (jdlx === "zhzx" || jdlx === "bzhkd" || jdlx === "bms") {
                  // 这几个是子节点
                  node["children"] = false;
                } else {
                  // ksgljg的，根据业务判断是否需要把县当成子节点
                  if (cxlxArr.length === 1) {
                    // cxlx只有 ksgljg， 那么县就是子节点
                    const jdid = item.id;
                    if (jdid) {
                      const xiancode = jdid.toString().trim().substring(4, 6);
                      if (Number(xiancode)) {
                        node["children"] = false;
                      }
                    }
                  }
                }
              } else {
                // 查询中有bzhkc ， 那么 zhzx bms bzhkc 是子节点
                if (jdlx == "zhzx" || jdlx == "bzhkc" || jdlx == "bms") {
                  node["children"] = false;
                } else if (jdlx == "bzhkd") {
                  node["children"] = true;
                } else {
                  //ksgljg, 因为cxlxv中有 bzhkc
                  node["children"] = true;
                }
              }


              if (jdlx == "bms") {
                bmslist.push(node);
              } else {
                notbmslist.push(node);
              }
            });
            // 排序吧 保密室节点放到最前面
            const childrenNodes = bmslist.concat(notbmslist ? notbmslist : []);
            callback(childrenNodes);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
            callback([]);
          }
        } else {
          this.initcstree("");
        }
      });
    });
  }


  /**
   * ###################################  业务树 （和考试计划有关系）     ##############################################
   * @param {string} flag
   * "" ----初始化构造
   * "refresh"---刷新场所树
   *  "removetree"--删除树实例，并重新生成树
   */
  initywtree(flag: string): void {
    if (flag === "refresh") {
      $("#tree").jstree("refresh");
      return;
    }
    if (flag == "removetree") {
      $("#tree").jstree("destroy");
    }
    const nodelx = this.o.nodelx;
    switch (nodelx) {
      case "ksgljg_kd":
        this.createtree_ksgljg_kd();
        break;
      case "kd":
        this.createtree_kd();
        break;
      case "ksgljg_kd_kc":
        //  Z1 Z2 Z3
        this.createtree_ksgljg_kd_kc();
        break;
      case "kd_kc":
        //   K
        this.createtree_kd_kc();
        break;
      case "kq_kd":
        this.createtree_kq_kd();
        break;
    }
  }

  /**
   * 节点是   ksgljg/kd   kd是子节点
   */
  createtree_ksgljg_kd(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata("createtree_ksgljg_kd", that.o.id, true, (data) => {
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text
                },
                data: {
                  bzhkdid: ''
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          } else {
            that.getnodedata("createtree_ksgljg_kd", node.id, true, (data) => {
              cb(data);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "kd": {
          "icon": "fa fa-university"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //ksgljgid/ kdbh
      const nodetext = selected.node.text;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          bzhkdid: selected.node.data.bzhkdid,
          nodetext: nodetext
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  /**
   * 节点是   kd   kd是子节点， 一个物理考点可能多个逻辑考点
   */
  createtree_kd(): void {
    let firstrootid: string = "";
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.kdNode(that.o.id, true, (data) => {
              firstrootid = data[0].id;
              cb(data);
            })
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "kd": {
          "icon": "fa fa-university"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //ksgljgid/ kdbh
      const nodetext = selected.node.text;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          bzhkdid: selected.node.data.bzhkdid,
          nodetext: nodetext
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = firstrootid;
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  /**
   * 节点是   ksgljg/kd/kc    kc 是子节点
   */
  createtree_ksgljg_kd_kc(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata("createtree_ksgljg_kd", that.o.id, true, (data) => {
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text
                },
                data: {
                  bzhkdid: ''
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          } else {
            const nodetype = node.type;
            if (nodetype === "ksgljg") {
              that.getnodedata("createtree_ksgljg_kd", node.id, false, (data) => {
                cb(data);
              });
            } else if (nodetype === "kd") {
              that.kcNode(node.id, true, (data) => {
                cb(data);
              });
            }
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "kd": {
          "icon": "fa fa-university"
        },
        "kc": {
          "icon": "fa fa-graduation-cap"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //ksgljgid/ kdbh/kcbh
      const nodetext = selected.node.text;
      const senddata = {
        nodeid: nodeid,
        nodetype: nodeType,
        bzhkdid: selected.node.data.bzhkdid,
        nodetext: nodetext,
      };
      if (nodeType == "kc") {
        senddata.nodeid = selected.node.data.kcbh; // 考场编号可能和考点编号一致，所以考点编号从 data里取
      }
      that.outhander.emit({
        type: "clicknode",
        data: senddata
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }


  /**
   * 节点是 kd /kc  -- kc是子节点
   */
  createtree_kd_kc(): void {
    const that = this;
    let firstnode_id: string = "";
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.kdNode(that.o.id, false, (data) => {
              firstnode_id = data[0].id;
              cb(data);
            });
          } else {
            const kdbh = node.id;
            that.kcNode(kdbh, true, (data) => {
              cb(data);
            })
          }
        },
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "kd": {
          "icon": "fa fa-university"
        },
        "kc": {
          "icon": "fa fa-graduation-cap"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //ksgljgid/ kdbh/kcbh
      const nodetext = selected.node.text;
      const senddata = {
        nodeid: nodeid,
        nodetype: nodeType,
        bzhkdid: selected.node.data.bzhkdid,
        nodetext: nodetext,
      }
      if (nodeType == "kc") {
        senddata.nodeid = selected.node.data.kcbh;
      }
      that.outhander.emit({
        type: "clicknode",
        data: senddata
      });
    }).on("loaded.jstree", function (obj) {
      const rootnodeid: string = firstnode_id;
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }


  createtree_kq_kd(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata("createtree_kq_kd", that.o.id, true, (data) => {
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text
                },
                data: {
                  bzhkdid: ''
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });

          } else {
            that.getnodedata("createtree_kq_kd", node.id, true, (data) => {
              cb(data);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "kd": {
          "icon": "fa fa-university"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      console.log(selected)
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //ksgljgid/ kdbh
      const nodetext = selected.node.text;
      const nodecclx = selected.node.original.type;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          bzhkdid: selected.node.data.bzhkdid,
          nodetext: nodetext,
          nodecclx: nodecclx
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }


  ajax_gettreedata_ksgljg(url: string, reqobj: any): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const treeList = resp.treeList;
              const childrenNodes = treeList.map((item) => {
                const node = {
                  id: item.id,
                  type: item.jdlx,
                  text: item.jdmc,
                  li_attr: {
                    title: item.jdmc,
                  },
                  data: {
                    bzhkdid: ""
                  },
                  children: true
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.createtree_ksgljg_kd();
          }
        });
      });
    });

  }

  ajax_gettreedata_kd(url: string, reqobj: any, kdleaf: boolean): any {
    if (!this.s_ksjhbh || !this.s_ksccbh) {
      return
    }
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
          if (arg1) {
            if (arg2) {
              const yglkdxxList = resp.yglkdxxList;
              const childrenNodes = yglkdxxList.map((item) => {
                const node = {
                  id: item.kdbh,
                  type: item.jdlx,
                  text: item.jdmc,
                  li_attr: {
                    title: item.jdmc,
                  },
                  data: {
                    bzhkdid: item.bzhkdid
                  },
                  children: !kdleaf
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.createtree_ksgljg_kd();
          }
        });
      });
    });
  }

  ajax_gettreedata_kq(url: string, reqobj: any): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const cxksXjkqxxLb = resp.cxksXjkqxxLb;
              if (cxksXjkqxxLb || cxksXjkqxxLb.length > 0) {
                const childrenNodes = cxksXjkqxxLb.map((item) => {
                  const node = {
                    id: item.kqbh,
                    type: item.cclx,
                    text: item.kqmc,
                    li_attr: {
                      title: item.kqmc,
                    },
                    data: {
                      bzhkdid: ""
                    },
                    children: true
                  }
                  return node;
                });
                resolve(childrenNodes);
              }

            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.createtree_kq_kd();
          }
        });
      });
    });

  }

  ajax_gettree_kd(url: string, reqobj: any, kdleaf: boolean): any {
    if (!this.s_ksjhbh || !this.s_ksccbh) {
      return
    }
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
          if (arg1) {
            if (arg2) {
              const cxksXjkdxxLb = resp.cxksXjkdxxLb;
              if (cxksXjkdxxLb || cxksXjkdxxLb.length > 0) {
                const childrenNodes = cxksXjkdxxLb.map((item) => {
                  const node = {
                    id: item.kdbh,
                    type: item.cclx,
                    text: item.kdmc,
                    li_attr: {
                      title: item.kdmc,
                    },
                    data: {
                      bzhkdid: item.bzhkdid
                    },
                    children: !kdleaf
                  }
                  return node;
                });
                resolve(childrenNodes);
              }

            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.createtree_kq_kd();
          }
        });
      });
    });
  }


  async getnodedata(fucmc: string, nodeid: string, kdleaf: boolean, callback: Function) {
    let cbnodeArr: any[] = [];
    switch (fucmc) {
      case "createtree_ksgljg_kd": {
        const ksgljglist = await this.ajax_gettreedata_ksgljg("ksyw/jcxxgl/slb", {
          id: nodeid,
          jdlx: "ksgljg",
          cxlx: "ksgljg"
        });
        const kdlist = await this.ajax_gettreedata_kd("ksyw/kwrycx/yglkdxxlb", {
          ksgljgid: nodeid,
          ksjhbh: this.s_ksjhbh,
          ccm: this.s_ksccbh
        }, kdleaf);
        cbnodeArr = ksgljglist.concat(kdlist ? kdlist : []);
      }
        break;
      case "createtree_kq_kd": {
        const kqlist = await this.ajax_gettreedata_kq("ksyw/dckssj/hqxjkqxxCx", {
          ksjhbh: this.s_ksjhbh,
          kqbh: nodeid
        });
        const kdlist = await this.ajax_gettree_kd("ksyw/dckssj/hqxjkdxxCx", {
          kqbh: nodeid,
          ksjhbh: this.s_ksjhbh,
          ccm: this.s_ksccbh
        }, kdleaf);
        cbnodeArr = kqlist.concat(kdlist ? kdlist : []);
      }
        break;
    }
    callback(cbnodeArr);
  }

  kdNode(bzhkdid: string, kdleaf: boolean, callback: Function): void {
    const url = "ksyw/ywjk/wlkdzljkd";
    this.itservice.kwPtPost(url, {
      bzhkdid: bzhkdid,
      ksjhbh: this.s_ksjhbh,
      ccm: this.s_ksccbh
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const wlkdzljkdLb = resp.wlkdzljkdLb;
            if (wlkdzljkdLb && wlkdzljkdLb.length) {
              const ljkdlist = wlkdzljkdLb.map((item, index) => {
                const kdbh = item.kdbh;
                const kdmc = item.kdmc;
                const kdnode = {
                  id: kdbh,
                  type: "kd",
                  text: kdmc,
                  li_attr: {
                    title: kdmc
                  },
                  data: {
                    kcbh: "",
                    bzhkdid: bzhkdid,
                  },
                  state: {
                    opened: false
                  },
                  children: !kdleaf
                }
                if (index == 0) {
                  kdnode.state.opened = true;

                }
                return kdnode;
              });
              callback(ljkdlist);
            } else {
              callback([])
            }
          }
        }
      });
    });
  }

  kcNode(kdbh: string, kcleaf: boolean, callback: Function): void {
    const url = "ksyw/ljkc/ljkcLb";
    this.itservice.kwPtPost(url, {
      ksjhbh: this.s_ksjhbh,
      ccm: this.s_ksccbh,
      kcmc: "",
      kcbh: "",
      kdbh: kdbh,
      pageNum: 1,
      pageSize: 9999
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const ljkcList = resp.ljkcList;
            const childrenNodes = ljkcList.map((item) => {
              const node = {
                // 考场编号可能和 考点编号一样，所以，要处理
                //id: item.kcbh,
                type: "kc",
                text: item.kcmc,
                li_attr: {
                  title: item.kcmc,
                },
                data: {
                  kcbh: item.kcbh,
                  bzhkdid: ""
                },
                children: !kcleaf
              }
              return node;
            });
            callback(childrenNodes);
          } else {
            callback([]);
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.kcNode(kdbh, kcleaf, callback);
        }
      });
    });
  }

  /**
   * ##################################场所业务树 （场所树上挂其他的节点）          ###################################
   * @param {string} flag
   * '' --- 初始化树
   * "refresh"--刷新树
   * "removetree"--删除树实例，并重新生成树
   */
  initcsywtree(flag: string): void {
    if (flag === "refresh") {
      $("#tree").jstree("refresh");
      return;
    }
    if (flag == "removetree") {
      $("#tree").jstree("destroy");
    }
    const nodelx = this.o.nodelx;
    switch (nodelx) {
      case "ksgljg_bzhkd_bms_nvr":
        this.createtree_ksgljg_bzhkd_bms_nvr();
        break;
      case "bzhkd_bms_nvr":
        this.createtree_bzhkd_bms_nvr();
        break;
      case "ksgljg_bzhkd_bsm_bzhkc_Andqtcs":
        this.createtree_ksgljg_bzhkd_bms_bzhkc_Andqtcs();
        break;
      case "bzhkd_bzhkc_Andqtcs":
        this.createtree_bzhkd_bzhkc_Andqtcs();
        break;
      case "ksgljg_bzhkd_bsm_bzhkc_Andqtcs_nocheckbox":
        this.createtree_ksgljg_bzhkd_bms_bzhkc_Andqtcs_nocheckbox();
        break;
      case "bzhkd_bzhkc_Andqtcs_nocheckbox":
        this.createtree_bzhkd_bzhkc_Andqtcs_nocheckbox();
        break;
      case "bsm_Andqtcs_nocheckbox":
        this.createtree_bsm_Andqtcs_nocheckbox();
        break;
    }
  }

  /**
   * 节点是  ksgljg/bzhkd/bms/nvr  nvr是子节点
   */
  createtree_ksgljg_bzhkd_bms_nvr(): void {
    const cxlx = "ksgljg,bzhkd,bms";
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getcsdata_yw(that.o.id, that.o.type, cxlx, (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {},
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          } else {
            const nodetype = node.type;
            if (nodetype === "ksgljg") {
              that.getcsdata_yw(node.id, node.type, cxlx, (data) => {
                cb(data);
              });
            } else {
              //bms bzhkd
              that.getNvrList(node.id, "nvr", (data) => {
                cb(data);
              });
            }
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "nvr": {
          "icon": "fa fa-server"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  /**
   * 节点是  bzhkd/bms/nvr    nvr是子节点
   */
  createtree_bzhkd_bms_nvr(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getNvrList(that.o.id, "nvr", (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {},
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "nvr": {
          "icon": "fa fa-server"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }


  getNvrList(csid: string, sblx: string, callback: Function): void {
    const url = "sbyw/sbgl/gjcsbhcxsblb";
    this.itservice.kwPtPost(url, {
      csbh: csid,
      sblx: sblx,
      pageNum: 1,
      pageSize: 99999
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const sbxxlb = resp.sbxxlb;
            const childrenNodes = sbxxlb.map((item) => {
              const node = {
                id: item.sbbh,
                type: "nvr",
                text: item.sbmc,
                li_attr: {
                  title: item.sbmc,
                },
                data: {},
                children: false
              }
              return node;
            });
            callback(childrenNodes);
          }
        } else {
          this.getNvrList(csid, sblx, callback);
        }
      });
    });
  }

  getcsdata_yw(id: string, type: string, cxlx: string, callback: Function): void {
    const url = "ksyw/jcxxgl/slb";
    this.itservice.kwPtPost(url,
      {
        id: id,
        jdlx: type,
        cxlx: cxlx
      }
    ).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
        if (flag) {
          if (flag2) {
            const treeList = resp.treeList;
            const childrenNodes = treeList.map((item) => {
              const jdlx = item.jdlx;
              const node = {
                id: item.id,
                type: jdlx,
                text: item.jdmc,
                li_attr: {
                  title: item.jdmc,
                },
                data: {},
                children: true
              }
              return node;
            });
            callback(childrenNodes);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
            callback([]);
          }
        } else {
          this.getcsdata_yw(id, type, cxlx, callback);
        }
      });
    });
  }


  /**
   * 节点是 ksgljg/bzhkd/bsm/ bzhkc/qtcs  qtcs是子节点  bzhkc是子节点
   */
  createtree_ksgljg_bzhkd_bms_bzhkc_Andqtcs(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        'check_callback': true,
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata2("cs_qtcs", that.o.id, that.o.type, (data) => {
                // 根节点信息从 登入用户信息来
                const rootNode = {
                  id: that.o.id,
                  type: that.o.type,
                  text: that.o.text,
                  li_attr: {
                    title: that.o.text,
                  },
                  data: {
                    sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                  },
                  state: {
                    opened: true
                  },
                  children: data
                };
                cb(rootNode);
              }
            )
            ;
          } else {
            const nodetype = node.original.type;
            if (nodetype === "ksgljg") {
              that.getnodedata2("cs_qtcs", node.id, node.type, (data) => {
                cb(data);
              });
            } else {
              //bzhkd 或者 bms  或者 bzhkc  或者其他场所
              if (nodetype == "bzhkd") {
                that.getnodedata2("bzhkcAndqtcs", node.id, "", (data) => {
                  cb(data);
                });
              } else if (nodetype == "bms") {
                that.getnodedata2("qtcs", node.id, "", (data) => {
                  cb(data);
                });
              }
            }
          }
        }
      },
      "plugins": ["checkbox", "types"],
      "checkbox": {
        "keep_selected_style": false,
        "three_state": false
      },
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bzhkc": {
          "icon": "fa fa-server"
        },
        "qtcs": {
          "icon": "fa fa-bookmark"
        },
        "sb": {
          "icon": "fa fa-video-camera"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.original.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const nodeparents = selected.node.parents;
      const parentid = selected.node.parent;//父级节点
      const parentlx = $("#tree").jstree('get_node', parentid).type;
      const sipuriv = selected.node.data.sipuri;
      const parentnode = $("#tree").jstree('get_node', selected.node.parent); //如果点击的是根节点，那么上面的节点 Id="#" type="#"

      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          nodeparents: nodeparents,
          parentid: parentid,
          parentlx: parentlx,
          sipuri: sipuriv,
          parentsipuri: parentnode.data ? parentnode.data.sipuri : ""
        }
      });
    })
  }

  /**
   * 节点是  bzhkd/bzhkc/qtcs     qtcs是子节点  bzhkc是子节点
   */
  createtree_bzhkd_bzhkc_Andqtcs(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata2("bzhkcAndqtcs", that.o.id, "", (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {
                  sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          }
        }
      },
      "plugins": ["checkbox", "types"],
      "checkbox": {
        "keep_selected_style": false,
        "three_state": false
      },
      "types": {
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bzhkc": {
          "icon": "fa fa-server"
        },
        "qtcs": {
          "icon": "fa fa-bookmark"
        },
        "sb": {
          "icon": "fa fa-video-camera"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.original.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const nodeparents = selected.node.parents;
      const parentid = selected.node.parent;//父级节点
      const parentlx = $("#tree").jstree('get_node', parentid).type;
      const sipuriv = selected.node.data.sipuri;
      const parentnode = $("#tree").jstree('get_node', selected.node.parent); //如果点击的是根节点，那么上面的节点 Id="#" type="#"
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          nodeparents: nodeparents,
          parentid: parentid,
          parentlx: parentlx,
          sipuri: sipuriv,
          parentsipuri: parentnode.data ? parentnode.data.sipuri : ""
        }
      });
    })
  }


  /**
   * 节点是 ksgljg/bzhkd/bsm/ bzhkc/qtcs  qtcs是子节点  bzhkc是子节点
   */
  createtree_ksgljg_bzhkd_bms_bzhkc_Andqtcs_nocheckbox(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        'check_callback': true,
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata2("cs_qtcs", that.o.id, that.o.type, (data) => {
                // 根节点信息从 登入用户信息来
                const rootNode = {
                  id: that.o.id,
                  type: that.o.type,
                  text: that.o.text,
                  li_attr: {
                    title: that.o.text,
                  },
                  data: {
                    sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                  },
                  state: {
                    opened: true
                  },
                  children: data
                };
                cb(rootNode);
              }
            )
            ;
          } else {
            const nodetype = node.original.type;
            if (nodetype === "ksgljg") {
              that.getnodedata2("cs_qtcs", node.id, node.type, (data) => {
                cb(data);
              });
            } else {
              //bzhkd 或者 bms  或者 bzhkc  或者其他场所
              if (nodetype == "bzhkd") {
                that.getnodedata2("bzhkcAndqtcs", node.id, "", (data) => {
                  cb(data);
                });
              } else if (nodetype == "bms") {
                that.getnodedata2("qtcs", node.id, "", (data) => {
                  cb(data);
                });
              }
            }
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bzhkc": {
          "icon": "fa fa-server"
        },
        "qtcs": {
          "icon": "fa fa-bookmark"
        },
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.original.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const nodeparents = selected.node.parents;
      const parentid = selected.node.parent;//父级节点
      const parentlx = $("#tree").jstree('get_node', parentid).type;
      const sipuriv = selected.node.data.sipuri;
      const parentnode = $("#tree").jstree('get_node', selected.node.parent); //如果点击的是根节点，那么上面的节点 Id="#" type="#"

      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          nodeparents: nodeparents,
          parentid: parentid,
          parentlx: parentlx,
          sipuri: sipuriv,
          parentsipuri: parentnode.data ? parentnode.data.sipuri : ""
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  /**
   * 节点是  bzhkd/bzhkc/qtcs     qtcs是子节点  bzhkc是子节点
   */
  createtree_bzhkd_bzhkc_Andqtcs_nocheckbox(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata2("bzhkcAndqtcs", that.o.id, "", (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {
                  sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bzhkc": {
          "icon": "fa fa-server"
        },
        "qtcs": {
          "icon": "fa fa-bookmark"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.original.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const nodeparents = selected.node.parents;
      const parentid = selected.node.parent;//父级节点
      const parentlx = $("#tree").jstree('get_node', parentid).type;
      const sipuriv = selected.node.data.sipuri;
      const parentnode = $("#tree").jstree('get_node', selected.node.parent); //如果点击的是根节点，那么上面的节点 Id="#" type="#"
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          nodeparents: nodeparents,
          parentid: parentid,
          parentlx: parentlx,
          sipuri: sipuriv,
          parentsipuri: parentnode.data ? parentnode.data.sipuri : ""
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }


  /**
   * 节点是 bms/qtcs    qtcs是子节点
   */
  createtree_bsm_Andqtcs_nocheckbox(): void {
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: function (node, cb) {
          if (node.id === "#") {
            that.getnodedata2("qtcs", that.o.id, "", (data) => {
              // 根节点信息从 登入用户信息来
              const rootNode = {
                id: that.o.id,
                type: that.o.type,
                text: that.o.text,
                li_attr: {
                  title: that.o.text,
                },
                data: {
                  sipuri: that.commservice.removeSpace(false, that.o.sipuri)
                },
                state: {
                  opened: true
                },
                children: data
              };
              cb(rootNode);
            });
          }
        }
      },
      "plugins": ["types"],
      "types": {
        "bms": {
          "icon": "fa fa-shield"
        },
        "qtcs": {
          "icon": "fa fa-bookmark"
        }
      }
    }).on("select_node.jstree", function (e, selected) {
      const nodeType = selected.node.original.type;
      const nodeid = selected.node.id; //csid
      const nodetext = selected.node.text;
      const nodeparents = selected.node.parents;
      const parentid = selected.node.parent;//父级节点
      const parentlx = $("#tree").jstree('get_node', parentid).type;
      const sipuriv = selected.node.data.sipuri;
      const parentnode = $("#tree").jstree('get_node', selected.node.parent); //如果点击的是根节点，那么上面的节点 Id="#" type="#"
      that.outhander.emit({
        type: "clicknode",
        data: {
          nodeid: nodeid,
          nodetype: nodeType,
          nodetext: nodetext,
          nodeparents: nodeparents,
          parentid: parentid,
          parentlx: parentlx,
          sipuri: sipuriv,
          parentsipuri: parentnode.data ? parentnode.data.sipuri : ""
        }
      });
    }).on("loaded.jstree", function () {
      const rootnodeid: string = that.o["id"];
      const rootnode = $("#tree").jstree('get_node', rootnodeid);
      $("#tree").jstree('activate_node', rootnode);//代码点击根节点
    });
  }

  ajax_getcslist(url: string, reqobj: any): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const treeList = resp.treeList;
              const childrenNodes = treeList.map((item) => {
                const jdlx = item.jdlx;
                const node = {
                  id: item.id,
                  type: jdlx,
                  text: item.jdmc,
                  li_attr: {
                    title: item.jdmc,
                  },
                  data: {
                    sipuri: that.commservice.removeSpace(false, item.sipuri)
                  },
                  children: true
                }
                if (jdlx == "bzhkc") {
                  node["children"] = false;
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              this.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            this.ajax_getcslist(url, reqobj);
          }
        });
      });
    });
  }

  ajax_getqtcslist(url: string, reqobj: any, qtcsleaf: boolean): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const treeList = resp.qtcsManagerList;
              const childrenNodes = treeList.map((item) => {
                const node = {
                  id: item.qtcsbsid,
                  type: "qtcs",
                  text: item.qtcsmc,
                  li_attr: {
                    title: item.qtcsmc,
                  },
                  data: {},
                  children: !qtcsleaf
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.ajax_getqtcslist(url, reqobj, qtcsleaf);
          }
        });
      });
    });
  }

  ajax_getbzhkclist(url: string, reqobj: any, kcleaf: boolean): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const treeList = resp.bzhkcManagerList;
              const childrenNodes = treeList.map((item) => {
                const node = {
                  id: item.bzhkcbh,
                  type: "bzhkc",
                  text: item.bzhkcmc,
                  li_attr: {
                    title: item.bzhkcmc,
                  },
                  data: {},
                  children: !kcleaf
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.ajax_getbzhkclist(url, reqobj, kcleaf);
          }
        });
      });
    });
  }

  async getnodedata2(fucmc: string, nodeid: string, nodetype: string, callback: Function) {
    let cbnodeArr: any[] = [];
    switch (fucmc) {
      case "cs_qtcs": {
        const cslist = await this.ajax_getcslist("ksyw/jcxxgl/slb", {
          id: nodeid,
          jdlx: nodetype,
          cxlx: "ksgljg,bzhkd,bms",
        });
        const qtcslist = await this.ajax_getqtcslist("ksyw/qtcs/qtcsxxLb", {
          glcsbsid: nodeid,
          qtcsmc: "",
          qtcslx: "",
          pageNum: 1,
          pageSize: 9999
        }, true);
        cbnodeArr = cslist.concat(qtcslist ? qtcslist : []);
      }
        break;
      case "bzhkcAndqtcs": {
        const bzhkclist = await this.ajax_getbzhkclist("ksyw/bzhkc/kcxxLb", {
          bzhkcmc: "",
          bzhkcbh: "",
          jgid: nodeid,
          jglx: "bzhkd",
          pageNum: 1,
          pageSize: 9999
        }, true);
        const qtcslist = await this.ajax_getqtcslist("ksyw/qtcs/qtcsxxLb", {
          glcsbsid: nodeid,
          qtcsmc: "",
          qtcslx: "",
          pageNum: 1,
          pageSize: 9999
        }, true);
        // const sblist = await this.ajax_getsblist("sbyw/sbgl/gjcsbhcxsblb", {
        //   csbh: nodeid,
        //   sblx:'',
        //   pageNum: 1,
        //   pageSize: 9999
        // }, true);
        cbnodeArr = bzhkclist.concat(qtcslist ? qtcslist : []);
      }
        break;
      case "qtcs": {
        const qtcs_bms_list = await this.ajax_getqtcslist("ksyw/qtcs/qtcsxxLb", {
          glcsbsid: nodeid,
          qtcsmc: "",
          qtcslx: "",
          pageNum: 1,
          pageSize: 9999
        }, true);
        cbnodeArr = qtcs_bms_list;
      }
        break;
    }
    callback(cbnodeArr);
  }


  ajax_getsblist(url: string, reqobj: any, sbleaf: boolean): any {
    const that = this;
    return new Promise(function (resolve, reject) {
      that.itservice.kwPtPost(url, reqobj).subscribe(resp => {
        that.commservice.handResponse("get", url, resp, (flag, resp, flag2) => {
          if (flag) {
            if (flag2) {
              const treeList = resp.sbxxlb;
              const childrenNodes = treeList.map((item) => {
                const node = {
                  id: item.sbbh,
                  type: "sb",
                  text: item.sbmc,
                  li_attr: {
                    title: item.sbmc,
                  },
                  data: {},
                  children: !sbleaf
                }
                return node;
              });
              resolve(childrenNodes);
            } else {
              that.commservice.myswal("warning", resp, "", "ts", null);
              resolve([]);
            }
          } else {
            that.ajax_getsblist(url, reqobj, sbleaf);
          }
        });
      });
    });
  }

  getsblist(csbh: string, cslx: string, sbleaf: boolean, callback: Function): void {
    this.itservice.kwPtPost("sbyw/sbgl/gjcsbhcxsblb", {
      csbh: csbh,
      sblx: '',
      pageNum: 1,
      pageSize: 9999
    }).subscribe(resp => {
      this.commservice.handResponse("get", "sbyw/sbgl/gjcsbhcxsblb", resp, (flag, resp, flag2) => {
        if (flag) {
          if (flag2) {
            const treeList = resp.sbxxlb;
            const childrenNodes = treeList.map((item) => {
              const node = {
                id: item.sbbh,
                type: "sb",
                text: item.sbmc,
                li_attr: {
                  title: item.sbmc,
                },
                data: {},
                children: !sbleaf
              }
              return node;
            });
            callback(childrenNodes);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);

          }
        } else {
          this.getsblist(csbh, cslx, sbleaf, callback);
        }
      });
    });
  }

  /**
   * treetype  cstree---场所  ywtree---和考试计划考试场次有关系
   * nodelx  树上要挂的节点类型（cstree）
   * id  ---
   * type
   * text
   * sipuri----从当前用户所属场所（考试管理机构，标准化考点，保密室详情里获取的）
   * ksjhbh---考试计划编号 （ywtree）
   * ksccbh ---考试场次编号（ywtree）
   * removetree  ---- true， 销毁树
   * clickroot----(cstree)默认是true, false--不点击根节点
   */
  @Input() o: any;
  @Output() outhander: EventEmitter<any> = new EventEmitter<any>();

  constructor(private itservice: MyhttpService,
              private commservice: CommService) {

  }

  ngOnInit() {
    if (this.o.treeheight) {
      // 传递该参数，那么就覆盖默认值 600px
      this.treeroomh = this.o.treeheight + "px";
    } else {
      const ajustHeight = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240;
      this.treeroomh = `${ajustHeight}px`;
    }
    this.treetype = this.o.treetype;
    if (this.treetype === "cstree") {
      this.initcstree("");
    } else if (this.treetype === "ywtree") {
      this.s_ksjhbh = this.o.ksjhbh;
      this.s_ksccbh = this.o.ksccbh;
      this.initywtree("");
    } else if (this.treetype === "csywtree") {
      this.initcsywtree("");
    }
  }

  ngOnChanges(changes: { [hs: string]: SimpleChange }) {
    const firstchange = changes.o.firstChange;
    if (!firstchange) {
      this.treetype = this.o.treetype;
      const removetree_refresh = this.o.removetree;
      if (this.treetype === "cstree") {
        if (removetree_refresh) {
          this.initcstree("removetree");
        } else {
          this.initcstree("refresh");
        }
      } else if (this.treetype === "ywtree") {
        this.s_ksjhbh = this.o.ksjhbh;
        this.s_ksccbh = this.o.ksccbh;
        if (removetree_refresh) {
          this.initywtree("removetree");
        } else {
          this.initywtree("refresh");
        }
      } else if (this.treetype == "csywtree") {
        if (removetree_refresh) {
          this.initcsywtree("removetree");
        } else {
          this.initcsywtree("refresh");
        }
      }
    }
  }
}
